package com.bsj.travel.util;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import com.bsj.crypt.crypt.aes.AESUtils;
import com.bsj.travel.util.uuid.UUID;

/**
 * @author LiJiaXin
 * @version 1.0.0
 * @description AesUtils
 * @time 2024/3/26 20:18
 */
public class AesUtils {

    /**
     * 加密
     *
     * @param secretKey 秘钥
     * @param content   加密内容
     * @return
     * @author ljx
     * @time 2024/3/26 20:20
     */
    public static String encrypt(String secretKey, String content) {
        //构建
        AES aes = SecureUtil.aes(secretKey.getBytes());
        //加密为16进制表示
        return aes.encryptHex(content);
    }

    /**
     * 解密
     *
     * @param secretKey 秘钥
     * @param content   被加密的内容
     * @return
     * @author ljx
     * @time 2024/3/26 20:26
     */
    public static String decrypt(String secretKey, String content) {
        //构建
        AES aes = SecureUtil.aes(secretKey.getBytes());
        //解密
        return aes.decryptStr(content, CharsetUtil.CHARSET_UTF_8);
    }


    public static void main(String[] args) {
//        String key = "uDn2YUkPAKZXMgueHZDvS8G8";
//        System.out.println("秘钥\t" + key + ",秘钥长度" + key.length());
////        String key = "16gstehy65*H%so!";
//        String test = encrypt(key, "你好啊");
//        System.out.println(test);
//        System.out.println(decrypt(key, test));
        String secret = "wic123jsb578!bsj";
        AESUtils.setSecret(secret);
        try {
            AESUtils.start();
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println(AESUtils.decrypt( "8fLvMqNtLSg00Lqgn187uw=="));
        System.out.println(AESUtils.decrypt( "G09HW0jIH6C6grNdvzqJWQ=="));
        System.out.println(AESUtils.decrypt( "8fLvMqNtLSg00Lqgn187uw=="));
        System.out.println(AESUtils.encrypt( "testyylink.com"));
    }

}
